package com.hx.er.service.manager.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import com.hx.er.bean.base.AnnouncementBean;
import com.hx.er.bean.base.RestraurantBean;
import com.hx.er.bean.base.UserBean;
import com.hx.er.bean.detail.CityDetailBean;
import com.hx.er.bean.detail.DistrictDetailBean;
import com.hx.er.bean.detail.StreetDetailBean;
import com.hx.er.dao.IContactDao;
import com.hx.er.dao.ILocationDao;
import com.hx.er.dao.IRestraurantDao;
import com.hx.er.dao.IUserDao;
import com.hx.er.service.manager.IManagerRestService;

public class ManagerRestServiceImpl implements IManagerRestService {

	@Autowired
	private IRestraurantDao restraurantDao;

	@Autowired
	private IContactDao contactDao;

	@Autowired
	private IUserDao userDao;

	@Autowired
	private ILocationDao locationDao;

	@Override
	public int updateRest(RestraurantBean restBean) {
		int count = this.restraurantDao.updateRest(restBean);
		return count;
	}

	@Override
	public RestraurantBean getRestById(long restId) {
		return this.restraurantDao.getRestById(restId);
	}

	@Override
	public UserBean getUserAliveById(long userId) {
		return this.userDao.getUserAliveById(userId);
	}

	@Override
	public UserBean getManagerByRestId(long restId) {
		return this.userDao.getManagerByRestId(restId);
	}

	@Override
	public AnnouncementBean getAnnAlive(AnnouncementBean announcementBean) {
		return this.contactDao.getAnnAlive(announcementBean);
	}

	@Override
	public List<StreetDetailBean> getStreetDetailList(Map<String, Object> conditions) {
		return this.locationDao.getStreetDetailList(conditions);
	}

	@Override
	public List<DistrictDetailBean> getDistrictDetailList(Map<String, Object> conditions) {
		return this.locationDao.getDistrictDetailList(conditions);
	}

	@Override
	public List<CityDetailBean> getCityDetailList(Map<String, Object> conditions) {
		return this.locationDao.getCityDetailList(conditions);
	}

	@Override
	public int updateRestAddr(RestraurantBean restBean) {
		return this.restraurantDao.updateRestAddr(restBean);
	}

	@Override
	@Transactional
	public int updateAnn(AnnouncementBean annBean) {
		int count = this.contactDao.deleteAnn(annBean);
		if (count != 0) {
			this.contactDao.insertAnnWithoutId(annBean);
			return 1;
		} else {
			return 0;
		}
	}

}
